<?php
include("../mysqlcon.php");
mysql_select_db($dbname,$conn);
mysql_query('SET NAMES utf8');
$inputDate = $_GET[date];
$id = $_GET['id'];

list($bYear, $bMonth, $bDay) = explode("-",substr($inputDate,0,10));
list($eYear, $eMonth, $eDay) = explode("-",substr($inputDate,11,10));
$bDate = mktime(0,0,0,$bMonth,$bDay,$bYear);
$eDate = mktime(0,0,0,$eMonth,$eDay,$eYear);
$reserv_begin = date("Y-m-d", $bDate);
$reserv_end = date("Y-m-d", $eDate);

/*$validatesql = "SELECT room_id FROM resort
WHERE roomtype_id = '$id' AND room_id NOT IN(SELECT DISTINCT reservation.room_id
FROM reservation WHERE '$reserv_begin' BETWEEN reservation.reserv_begin AND reservation.reserv_end)";*/

$validatesql = "SELECT room_id FROM resort
WHERE roomtype_id = '$id' AND room_id NOT IN(SELECT DISTINCT reservation.room_id
FROM reservation WHERE reserv_status != '2' AND (`reserv_end` > '$reserv_begin' AND `reserv_end` <= '$reserv_end'
OR `reserv_begin` >= '$reserv_begin' AND `reserv_begin` <= '$reserv_end'))";

	$r = mysql_query($validatesql,$conn);
	echo "[";
	while ($rs = mysql_fetch_array($r))
	{
	   echo "{optionValue: '$rs[room_id]', optionDisplay: '$rs[room_id]'}, ";
		//echo $rs[room_id];
		//echo "<br>";
	}
	echo "]";
?>
